{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> 公众号《凹凸玩数据》"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "数据的分布形态描述是最形象的描述方式,因为可以用各种统计图形将数据的分布形态展现在图形中,让人一目了然.通常我们研究概率分布主要是研究各种分布的公式,均值,方差,分布以及常用实例."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 离散变量概率分布"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "离散型概率分布是一条条垂直于X轴的垂线(或矩形柱),每条垂线与X轴的交点代表事件可能发生的结果,垂线上端点对应的Y轴表示该结果发生的概率.常见的离散型概率分布有伯努利分布,二项分布和泊松分布等."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from scipy.stats import bernoulli\n",
    "from scipy.stats import binom\n",
    "from scipy.stats import poisson"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 二项分布"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "二项分布（Binomial distribution）是n个独立的是/非试验中成功的次数的离散概率分布，其中每次试验的成功概率为p。实际上单次的成功/失败试验就是一次伯努利试验;当n=1时,二项分布就是伯努利分布."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "二项分布的**公式**表达为:\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "f(k;n,p)=Pr(X=k)=\\left(_k^n\\right)p^k(1-p)^{n-k}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对于k=0, 1, 2,...,n,其中$\\left(_k^n\\right)=\\frac{n!}{k!(n-k)!}$是二项式系数（这就是二项分布的名称的由来），又记为C(n,k)。该公式可以用以下方法理解：我们希望有$k$次成功$(p^k)$和$n−k$次失败$(1−p)^{n−k}$。然而，k次成功可以在n次试验的任何地方出现，而把k次成功分布在n次试验中共有C(n, k)个不同的方法。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**期望值**为:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "E[X]=np\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**方差**为:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "Var[X]=np(1-p)\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0, 0.5, 'probability')"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEWCAYAAACXGLsWAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAHOJJREFUeJzt3XmUHXWd/vH3QyJr2BNnnCwGJIPiDItG4giCC2o4KGFGFBQQFA/HUUQH+XmCC2AcZzLiNiIqKAFUFBFBwxAFZJNFMAlLICgSQoAmCNGwCgKB5/dHfRtvmu6u26Grb9N5Xufcc2v7Vn0qNPe5tdxvyTYRERH9WafTBURExPCXsIiIiFoJi4iIqJWwiIiIWgmLiIiolbCIiIhaCYvolaRvS/rscN6upMskfbDpmgaTpEclbd3P/GWS9hjKmiLakbBYS5UPpcfLh9cDks6XNLF7vu0P2f78UNc1WNuVdJykp8r+db8+WeZdJsmSdujR5mdl+hvq1rGmbI+xvbSs/zRJ//l81jcYJL1b0tWSHpN0WS/zd5S0sMxfKGnHIajpzZJ+X7Z5q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UZERP8a7RvK9jxgXo9px7QM79FP2znAnOaqi4iIduUX3BERUSthERERtRIWERFRK2ERERG1EhYREVErYREREbUSFhERUSthERERtRIWERFRK2ERERG1EhYREVErYREREbUSFhERUSthERERtRIWERFRK2ERERG1EhYREVErYREREbUSFhERUSthERERtRIWERFRK2ERERG1EhYREVErYREREbUSFhERUSthERERtRIWERFRK2ERERG12goLSaOaLiQiIoavdo8slkg6XtJ2jVYTERHDUrthsT3wB+C7kq6RdJikTRqsKyIihpG2wsL2I7a/Y/t1wCeBY4F7JZ0uaZtGK4yIiI5r+5qFpL0lnQv8L/BlYGvgPGBeg/VFRMQw0O5pqNuAGcDxtney/RXb99k+G/hlX40kTZd0q6Qlkmb2Mn83SddJWiVp3x7znpZ0Q3nNHchORUTE4Brd5nLvs31l6wRJu9i+yvYRvTUod1CdCLwF6ALmS5pr+5aWxe4CDgGO6mUVj9vesc36IiKiQe0eWXy9l2kn1LTZGVhie6ntJ4EzqY5OnmV7me1FwDNt1hERER3Q75GFpH8BXgeMk3Rky6xNgLrfXowH7m4Z7wKmDaC29SUtAFYBs23/rJf6DgMOA5g0adIAVh0REQNRdxpqXWBMWW7jlukPA/v22uJv1Ms0t18ak2wvl7Q1cImkm2zfvtrK7JOBkwGmTp06kHVHRMQA9BsWti8HLpd0mu07B7juLmBiy/gEYHm7jW0vL+9LJV0G7ATc3m+jiIhoRN1pqK/Z/jjwDUnP+eZue+9+ms8HpkjaCrgH2B94bztFSdoceMz2E5LGArsAX2ynbUREDL6601DfL+9fGuiKba+SdDhwAdX1jTm2F0uaBSywPVfSa4Bzgc2Bd0j6nO1XAq8ATpL0DNVF+Nk97qKKiIghVHcaamF5v3xNVm57Hj1+tGf7mJbh+VSnp3q2uxr45zXZZkREDL6601A30c9FadvbD3pFEREx7NSdhnr7kFQRERHDWt1pqIHeARURESNQv7/glnRleX9E0sM934emxIiI6LS6I4tdy/vG/S0XEREjW7sdCSLpVcCuVBe8r7R9fWNVRUTEsNLu8yyOAU4Ht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qHZPQ63J9YL5wBRJWwH3APsD722z7QXAf0navIy/FTh6DWqIiIhB0FZY2L5zoCu2vUrS4VQf/KOAObYXS5oFLLA9V9JrgHOBzYF3SPqc7VfaXinp81SBAzDL9sqB1hAREYOj3SOLNWJ7HjCvx7RjWobnU51i6q3tHKqu0SMiosPavWYRERFrsYRFRETUSlhERESthEVERNRKWERERK2ERURE1EpYRERErYRFRETUSlhERESthEVERNRKWERERK2ERURE1EpYRERErYRFRETUSlhERESthEVERNRKWERERK2ERURE1EpYRERErYRFRETUSlhERESthEVERNRKWERERK2ERURE1EpYRERErYRFRETUSlhERESthEVERNRKWERERK2ERURE1EpYRERErYRFRETUSlhEREStRsNC0nRJt0paImlmL/PXk/TjMv9aSZPL9MmSHpd0Q3l9u8k6IyKif6ObWrGkUcCJwFuALmC+pLm2b2lZ7FDgAdvbSNof+B9gvzLvdts7NlVfRES0r8kji52BJbaX2n4SOBOY0WOZGcDpZfhs4M2S1GBNERGxBpoMi/HA3S3jXWVar8vYXgU8BGxZ5m0l6XpJl0t6fW8bkHSYpAWSFqxYsWJwq4+IiGc1GRa9HSG4zWXuBSbZ3gk4EvihpE2es6B9su2ptqeOGzfueRccERG9azIsuoCJLeMTgOV9LSNpNLApsNL2E7b/DGB7IXA78I8N1hoREf1oMizmA1MkbSVpXWB/YG6PZeYCB5fhfYFLbFvSuHKBHElbA1OApQ3WGhER/WjsbijbqyQdDlwAjALm2F4saRawwPZc4BTg+5KWACupAgVgN2CWpFXA08CHbK9sqta1yeSZ569Ru2Wz9xrkSiLihaSxsACwPQ+Y12PaMS3DfwXe1Uu7nwI/bbK2iIhoX6NhERExGHJE3Hnp7iMiImolLCIiolbCIiIiaiUsIiKiVsIiIiJqJSwiIqJWwiIiImolLCIiolbCIiIiaiUsIiKiVsIiIiJqJSwiIqJWwiIiImolLCIiolbCIiIiaiUsIiKiVsIiIiJqJSwiIqJWwiIiImolLCIiolbCIiIiaiUsIiKiVsIiIiJqJSwiIqJWwiIiImolLCIi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ujxb4xzbt1VdGz2XpI2pPuTPLfX+tUzfAzjV9mNl+srSa/DrgJ+0rG+98n4VcJqks6g63OurjjdTBcP8so4NqDqrOw/YWtIJwPn0coQVI1/CIoarJ1qGn6b64ILqiKP79GnPx2i2tnmmZfwZVv9b79nHjam6pH+n7VtbZ0iaRtXNd296/5Tvh+0fSrqW6iFMF0j6INVRTOsp4e796mv94rn7sA7woO0de9nmh8p+7AXcIGnHPuoQcLrto5+zQWkH4G3AR4B3Ax9ob49jpMg1i3ihWUb17Rdg3zVcx34AknalemjOQ1QdRn609GCKpJ3aWM+vgX1Kz6cbAf8KXNFfA0lbA0ttf52qF9HtgfuAF0vaUtJ6wNsBXD1XpEvSPqXtepI2pPpm/4EyjKQtyrJ3SHpXmabyAY+kl9m+1vYxwJ+AiX3UcTGwr6QXd69X0ksljQXWsf1T4LOMzC7Po0aOLOKF5ktUPW8eBFyyhut4QNLVwCb87Rvy56mepLeoBMYyyod2X2xfJ+k04Ldl0ndt93cKCqqgOlDSU8AfgVm2n5I0i+r6xB3A71uWPwg4qcx/CniX7V9K2hFYIOlJYB7wKeAA4FuSPgO8iOq5HTcCx5cL2KIKhBupHojUs46Vpe2FktYp2/sI8DjVk/e6v1w+58gjRr70OhsREbVyGioiImolLCIiolbCIiIiaiUsIiKiVsIiIiJqJSwiIqJWwiIiImr9fwWVA7BOdHPZAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 利用plt模拟二项分布\n",
    "n , p =10 ,0.5\n",
    "sample = np.random.binomial(n, p, size=10000)  # 产生10000个符合二项分布的随机数\n",
    "bins = np.arange(n + 2)\n",
    "plt.hist(sample, bins=bins, align='left',density=True, rwidth=0.5)  # 绘制直方图\n",
    "# 设置标题和坐标\n",
    "plt.title('Binomial FMF with n={},p={}'.format(n, p))\n",
    "plt.xlabel('number of successes')\n",
    "plt.ylabel('probability')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 伯努利分布"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "现实生活中许多事件或活动的结果往往只有两个.抛硬币问题(正面/反面),产品质量检验问题(合格/不合格),投票选举问题(支持/不支持)等.如果某事件或活动的结果多于两个,但只关心其中一个,也可视为只有两个结果,比如奥运会中国乒乓球队是否获得金牌(排名有很多,奖牌也分为金银铜三种,但这里我们只关心是否拿金牌,也就是只有两个结果,获得金牌或未获得金牌).对于以上类似事件,在实际运用中,一般用\"成功\"表示我们感兴趣的发生结果(比如合格,支持,获得金牌等),用\"失败\"表示我们不感兴趣的结果.这一类事件或活动被称为伯努利试验.  \n",
    "\n",
    "伯努利分布(Bernoulli distribution)，又名两点分布或者0-1分布，是一个离散型概率分布.若伯努利试验成功，则伯努利随机变量取值为1。若伯努利试验失败，则伯努利随机变量取值为0。记其成功概率为$p(0≤p≤1)$,失败概率为$q=1-p$,则伯努利分布的**公式**表达为:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "f_X(x)=p^x(1-p)^{1-x}=\\begin{cases}\n",
    "p, \\quad if& x=1\\\\\n",
    "q, \\quad  if& x=0\n",
    "\\end{cases}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**期望值**为:\n",
    "$$\n",
    "E[X]=\\sum_{i=0}{1}x_if_X(x)=0+p=p\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**方差**为:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "var[X]=\\sum_{i=0}{1}=(x_i-E[X])^2f_X(x)=(0-p)^2(1-p))+(1-p)^2p=p(1-p)=pq\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, '伯努利分布：p=0.50')"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAEUCAYAAAAr20GQAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAG3NJREFUeJzt3XuYXVV9//H3hwQkBilYYhQwRirgDQFNrVi0qYpotZVSAW+opf1FrI+2P1qqIlZFWipYWuxP1NggttX2hxWDd2hVilpoTQqIN7RSvASxUSARBMTw7R9rDZkMc0ucMzPJvF/Pw5Nz9lln7+85JPtz1lr7kqpCkqSdZroASdLsYCBIkgADQZLUGQiSJMBAkCR1BoJ2aEl2SpKZrkPaHhgImhFJDk9yyrDnz0ryN+O0f3qShZNY7x5JHpdkRZILgB8ALx32+mFJPj/Gex/e/9wvyVMmsa2dkvxrkodM1FbaHsyf6QI0Z70Y+OGw548DbhjZKMkuwK7Ae4Bf6MuOB5YAm3qzr1bVRf3xnwCPAhYA1wOHVtW3hq3yDuCuUbbzLOAtSQ4CCliZ5DFV9eNxPsMzgfuOWP+0SnIi8Ebgu8AxVfXf47R9IO07uaUvuqyqjk0yD3gncBRwKfCiqrpzgGVrlrKHoGmXZC/g+cDbkxyX5CrgVcCLklzV/zuj76i+AFwL/BT4fJIf0oJjBfAlWpAsGVp3VZ1UVUcCFwLXDe2skzw/yftoO/uR9ewEvAF4XTX/DXwc+KsR7Q5Lcn2SL/WaPwDcf1jNVyW5OsmXkyyfwq9sVD28Xg88Fngl8P8meMshwHur6oH9v2P78hOBpcA+wH8Cvz+YijXb2UPQTDgF2FRV303yc8Dqqnrj0ItJngYcX1WbkjwO+A/ar9cDgGOr6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3yCOBro72eZPEoPYWpqukBVTXn71Ot7ZeBIEkCnEOQJHUGgiQJMBAkSZ2BIEkC4H8BgBBdbA7tUvEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 利用plt模拟伯努利分布\n",
    "#解决画图中文乱码\n",
    "plt.rcParams['font.sans-serif']=['SimHei']\n",
    "plt.rcParams['axes.unicode_minus']=False\n",
    "#定义随机变量\n",
    "X = np.arange(10) \n",
    "p = 0.5\n",
    "#伯努利概率函数\n",
    "pList = bernoulli.pmf(X,p)\n",
    "#绘图，marker：点的形状，linestyle：线条的形状\n",
    "plt.plot(X,pList,marker = 'o',linestyle = 'None' )\n",
    "#vlines绘制树直线，参数的含义（x轴坐标轴，y轴最小值，y轴最大值）\n",
    "plt.vlines(X,0,pList)\n",
    "plt.xlabel(\"随机变量：抛硬币{}次\".format(len(X)))\n",
    "plt.ylabel(\"概率\")\n",
    "plt.title('伯努利分布：p={:.2f}' .format(p))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 泊松分布"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "泊松分布考虑的是在连续时间或空间单位上发生的随机事件次数的概率.换句话说,基于过去某个随机事件在某段时间或某个空间内发生的平均次数,如某一服务设施在一定时间内受到的服务请求的次数，电话交换机接到呼叫的次数、汽车站台的候客人数、机器出现的故障数、自然灾害发生的次数、DNA序列的变异数、放射性原子核的衰变数、激光的光子数分布等等。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "泊松分布的**公式**表达为:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "P(X=k)=\\frac{e^{-\\lambda}\\lambda^k}{k!}\n",
    "$$\n",
    "参数λ是单位时间（或单位面积）内随机事件的平均发生率."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**期望值**为:\n",
    "$$\n",
    "E(X)=\\lambda\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**方差**为:\n",
    "$$\n",
    "Var(X)=E(X)=\\lambda\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "假设通过一定时间的观察，我们知道某个路口每小时平均有8辆车通过，这是一个典型的泊松分布实例，我们通过Python进行统计模拟来看看在统计图它具体是如何呈现的。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYcAAAERCAYAAACQIWsgAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAGnxJREFUeJzt3X+8HXV95/HX21R9YLCKGqJYMY1LrVqNYlCioMGClmLLmlWh/hYtlqrd1odVrHGtXeoD0aVrfWjXKAjUH7vQVbSiFV2MoAKaqKiILloDgqKh0KRYu1r87B8z11zv3HvP3Hjmnpvk9Xw8zuPMmfOZmc+Z5J7Pme93vjOpKiRJmu4Ok05AkrT0WBwkSR0WB0lSh8VBktRhcZAmKEkmncM47C2fQ7tYHKQJSXIH4IIkB046lzF4/17yOdSyOGiskjwvyY+SfD/Jd5P82UDbeX+Sxwyw3nOS7EiyPcm1SY5t529L8uF2+ulJKsn6JJuT3JLkpmmP+/Xc3MuAT1fVD6Ztf3OS9b9A/iOXT7IqybbdXP+dknwgyfeSfCXJo9u3Xg+8Y3fWqaXJ4qAhfLCqVgIPA547xJd4VW2oqs+Oe72tV1bVCuD3gHcl2b+d/5D2+cEz4p9RVfee9vjOqA0kuRvwO8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osDpKkDouDJKnj/wMKDgl9nTW/aAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 用plt模拟泊松分布\n",
    "lamb = 8\n",
    "sample = np.random.poisson(lamb, size=10000)\n",
    "bins = np.arange(20)\n",
    "plt.hist(sample, bins=bins, align='left',density=True, rwidth=0.5)\n",
    "plt.title('Possion PMF (lambda=8)')\n",
    "plt.xlabel('number of appear')\n",
    "plt.ylabel('probability')\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
